home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Apple Developer Connection Student Program
/
ADC Tools Sampler CD Disk 3 1999.iso
/
Cool Demos, SDKs, & Tools
/
Demos⁄Tools⁄Offers
/
Eiffel for CW beta 3
/
Example Projects
/
EiffelText
/
EiffelText.h
< prev
next >
Wrap
Text File
|
1999-02-21
|
18KB
|
488 lines
/*
File: EiffelText.h
Contains: defines input for both .c and .r files.
structured so as to compile corrected in both.
Version: EiffelText 1.0
** Copyright 1993-1996 Apple Computer. All rights reserved.
**
** You may incorporate this sample code into your applications without
** restriction, though the sample code has been provided "AS IS" and the
** responsibility for its operation is 100% yours. However, what you are
** not permitted to do is to redistribute the source as "DSC Sample Code"
** after having made changes. If you're going to re-distribute the source,
** we require that you make it clear in the source that the code was
** descended from Apple Sample Code, but that you've made changes.
** YES - THIS HAS BEEN CHANGED FOR EIFFEL TEXT.
*/
#ifndef __SIMPLETEXT__
#define __SIMPLETEXT__
#define kScrollBarSize 15 // size of a scroll bar, in pixels
// Internal errors -- WARNING: some also appear in SimpleText.r
#define eActionAlreadyHandled 100 // the action was handled by the object, don't report an error
#define eUserCanceled 101 // user canceled an operation
#define eDocumentTooLarge 200 // document too large to be opened
#define eDocumentWrongKind 201 // document cannot be opened by this application
#define eErrorWhileDrawing 202 // error while drawing the document
#define eDocumentContainsPS 203 // document contains PostScript, it may not display properly
#define eMachineToOld 204
#define eDocumentNotModifiable 205 // document can't be modified
#define eDocumentAlreadyOpen 206
#define eDocumentContainsNoPages 207
#define eDocumentHasNoContentsEntries 208
// icon IDs -- WARNING: Also appear in SimpleText.r
#define kTextIcon 129
#define kReadOnlyIcon 130
#define kPICTIcon 131
#define kStationeryIcon 132
// menu and item defines -- define 'MENU' 'MCMD' 'hmnu' and 'STR#' IDs for menus!
#define rMenuBar 128
#define mApple 128
#define mFile 129
#define mEdit 130
#define mFont 131
#define mSize 132
#define mStyle 133
#define mSound 134
#define mVoices 135
#define mContents 136
#define mLastMenu mContents
#define mNumberMenus 9
#define mFontSubMenusStart 200
// Command numbers
#define cNull 0
#define cAbout 1
#define cDeskAccessory 2
#define cTypingCommand 3
#define cNew 10
#define cOpen 11
#define cClose 12
#define cSave 13
#define cSaveAs 14
#define cPageSetup 15
#define cPrint 16
#define cPrintOneCopy 17
#define cQuit 18
#define cUndo 20
#define cCut 21
#define cCopy 22
#define cPaste 23
#define cClear 24
#define cSelectAll 25
#define cFind 26
#define cFindAgain 27
#define cFindSelection 28
#define cReplace 29
#define cReplaceAgain 30
#define cNextPage 31
#define cPreviousPage 32
#define cGotoPage 33
#define cGotoLast 32767
#define cGotoFirst -32767
#define cShowClipboard 34
#define cSelectFont 35
#define cSelectFontStyle 36
#define cSize9 40
#define cSize10 41
#define cSize12 42
#define cSize14 43
#define cSize18 44
#define cSize24 45
#define cSize36 46
#define cPlain 50
#define cBold 51
#define cItalic 52
#define cUnderline 53
#define cOutline 54
#define cShadow 55
#define cCondensed 56
#define cExtended 57
#define cRecord 60
#define cPlay 61
#define cErase 62
#define cSpeak 63
#define cStopSpeaking 64
#define cSelectVoice 65
#define cSelectVoiceSubMenu 66
#define cSelectContents 75
// windows, dialogs, alerts, and other items of that sort
#define kDefaultWindowID 128
#define kSaveChangesWindowID 129
#define kFindWindowID 130
#define kReplaceWindowID 131
#define iFindEdit 4
#define iCaseSensitive 5
#define iWrapAround 6
#define iReplaceEdit 8
#define iReplaceAll 9
// Error STR# base
#define kErrorBaseID 1000
// Help for window STR#
#define kWindowHelpID 2000
#define iDidTheBalloon -1
#define iNoBalloon 0
#define iHelpActiveScroll 1
#define iHelpDimHorizScroll 2
#define iHelpDimVertScroll 3
#define iHelpGrowBox 4
#define iHelpGenericContent 5
#define iHelpPictContent 6
#define iHelpPictSelection 7
#define iHelpTextContent 8
// Miscellaneous strings (STR#)
#define kMiscStrings 3000
#define iFirstNewDocumentTitle 1
#define iHelpMenuCommand 2
#define iSelectAllCommand 3
#define iSelectNoneCommand 4
// Patterns used for selections
#define kPatternListID 128
// for disabling menu items
#define AllItems 0b1111111111111111111111111111111 /* 31 flags */
#define NoItems 0b0000000000000000000000000000000
#define MenuItem1 0b0000000000000000000000000000001
#define MenuItem2 0b0000000000000000000000000000010
#define MenuItem3 0b0000000000000000000000000000100
#define MenuItem4 0b0000000000000000000000000001000
#define MenuItem5 0b0000000000000000000000000010000
#define MenuItem6 0b0000000000000000000000000100000
#define MenuItem7 0b0000000000000000000000001000000
#define MenuItem8 0b0000000000000000000000010000000
#define MenuItem9 0b0000000000000000000000100000000
#define MenuItem10 0b0000000000000000000001000000000
#define MenuItem11 0b0000000000000000000010000000000
#define MenuItem12 0b0000000000000000000100000000000
#define MenuItem13 0b0000000000000000001000000000000
#define MenuItem14 0b0000000000000000010000000000000
#define MenuItem15 0b0000000000000000100000000000000
#define MenuItem16 0b0000000000000001000000000000000
#define MenuItem17 0b0000000000000010000000000000000
#define MenuItem18 0b0000000000000100000000000000000
#define MenuItem19 0b0000000000001000000000000000000
// Size resource information
#define kPreferredSize 512*1024
#define kMinimumSize 192*1024
#ifndef REZ
enum {
// Keyboard virtual keycode constants
kHome = 0x73,
kEnd = 0x77,
kPageUp = 0x74,
kPageDown = 0x79,
kUpArrow = 0x7E,
kDownArrow = 0x7D,
kLeftArrow = 0x7B,
kRightArrow = 0x7C,
kF1 = 0x7A,
kF2 = 0x78,
kF3 = 0x63,
kF4 = 0x76,
kFromTopTipOffset = 20, // offset from top/left of balloons
kFromBottomTipOffset = 7, // offset from bottom/right of balloons
kRAMNeededForNew = 64*1024, // amount of RAM free before we allow New documents
kGrowScrollAdjust = 13, // amount to cull scroll bar to make room for growbox
kMinDocSize = 128 // min window size in pixels
};
enum
{
kMaxWaitTime = 5*60*60 // maximum time to pass to WaitNextEvent()
};
struct MachineInfoRec
{
SysEnvRec theEnvirons; // SysEnvirons for this machine
Boolean amInBackground; // are we running in the background or foreground
long documentCount; // # of new docs we have made
short lastBalloonIndex; // identifier of last balloon we displayed
Boolean haveQuickTime; // do we have QuickTime installed?
Boolean haveRecording; // do we have sound input?
Boolean haveTTS; // do we have text to speech?
Boolean haveGX; // do we have GX?
Boolean haveTSM; // do we have text services?
Boolean haveTSMTE; // have inline support for TE?
Boolean haveDragMgr; // do we have the Drag Manager?
Boolean haveThreeD; // do we have 3D on this machine?
Boolean haveAppleGuide; // do we have AppleGuide?
Boolean haveThreads; // do we have threads?
Boolean haveStartedGX; // have initialized GX
};
typedef struct MachineInfoRec MachineInfoRec, *MachineInfoPtr;
#ifndef CompilingMain
extern MachineInfoRec gMachineInfo;
extern EventRecord gEvent;
extern Str255 gFindString, gReplaceString;
extern Boolean gWrapAround, gCaseSensitive;
#endif
struct PreflightRecord
{
Boolean continueWithOpen; // continue with the opening of the window
Boolean needResFork; // create resfork if none exists
SignedByte openKind; // kind of opening of this file
short resourceID; // resource ID of the 'WIND' resource
Boolean wantHScroll; // want a horizontal scroll bar
Boolean wantVScroll; // want a vertical scroll bar
Boolean doZoom; // want window opened large
long storageSize; // data for the window's refCon
void * makeProcPtr; // pointer to the make proc
OSType fileType; // file type of document
};
typedef struct PreflightRecord PreflightRecord, *PreflightPtr;
struct LongRect
{
long top;
long left;
long bottom;
long right;
};
typedef struct LongRect LongRect;
typedef OSErr (*PreflightWindowProc) (PreflightPtr pPreflightData);
typedef OSErr (*MakeWindowProc) (WindowRef pWindow, void* refCon);
typedef OSErr (*UpdateWindowProc) (WindowRef pWindow, void* refCon);
typedef OSErr (*AdjustMenusProc) (WindowRef pWindow, void* refCon);
typedef OSErr (*CloseWindowProc) (WindowRef pWindow, void* refCon);
typedef OSErr (*GetDocumentRectProc) (WindowRef pWindow, void* refCon, LongRect * documentRectangle, Boolean forGrow);
typedef OSErr (*ContentClickProc) (WindowRef pWindow, void* refCon, EventRecord * event);
typedef OSErr (*ScrollContentProc) (WindowRef pWindow, void* refCon, short deltaH, short deltaV);
typedef Boolean (*FilterEventProc) (WindowRef pWindow, void* refCon, EventRecord * event);
typedef OSErr (*ActivateEventProc) (WindowRef pWindow, void* refCon, Boolean activating);
typedef OSErr (*KeyEventProc) (WindowRef pWindow, void* refCon, EventRecord * event, Boolean isMotionKey);
typedef OSErr (*AdjustSizeProc) (WindowRef pWindow, void* refCon, Boolean *didResize);
typedef OSErr (*CommandProc) (WindowRef pWindow, void* refCon, short commandID, long menuResult);
typedef OSErr (*AdjustCursorProc) (WindowRef pWindow, void* refCon, Point * localMouse, Rect *globalRect);
typedef OSErr (*PrintPageProc) (WindowRef pWindow, void* refCon, Rect* pageRect, long* pageNum);
typedef OSErr (*GetBalloonProc) (WindowRef pWindow, void* refCon, Point *localMouse, short * returnedBalloonIndex, Rect *returnedRectangle);
typedef OSErr (*DragTrackingProc) (WindowRef pWindow, void *refCon, DragReference theDragRef, short message);
typedef OSErr (*DragReceiveProc) (WindowRef pWindow, void *refCon, DragReference theDragRef);
typedef OSErr (*DragAddFlavorsProc) (WindowRef pWindow, void *refCon, DragReference theDragRef);
typedef long (*CalculateIdleTimeProc) (WindowRef pWindow, void* refCon);
typedef OSErr (*GetCoachRectangleProc) (WindowRef pWindow, void* refCon, Rect *pRect, Ptr name);
struct WindowDataRecord
{
WindowRecord theWindow; // toolbox storage
ResType windowKind; // and kind to identify window type
OSType originalFileType; // original source of file
FSSpec fileSpec; // file spec of the file
short dataRefNum; // data fork refNum
short resRefNum; // res fork refNum
Boolean isWritable; // can you write to this file?
Boolean bumpUntitledCount; // does this kind of document use up an "untitled" number?
Boolean openAsNew; // open as an untitled document?
Boolean changed; // has content changed?
Boolean documentOutputsGX; // document provides GX printing
Boolean documentAcceptsText; // document allows typing
Boolean dragWindowAligned; // drag using DragAlignedWindow
// Standard procedure entry points, may be NIL to get default behavior
PreflightWindowProc pPreflightWindow;
MakeWindowProc pMakeWindow;
CloseWindowProc pCloseWindow;
GetDocumentRectProc pGetDocumentRect;
ScrollContentProc pScrollContent;
AdjustSizeProc pAdjustSize;
AdjustCursorProc pAdjustCursor;
GetBalloonProc pGetBalloon;
DragTrackingProc pDragTracking;
DragReceiveProc pDragReceive;
DragAddFlavorsProc pDragAddFlavors;
FilterEventProc pFilterEvent;
ActivateEventProc pActivateEvent;
UpdateWindowProc pUpdateWindow;
AdjustMenusProc pAdjustMenus;
KeyEventProc pKeyEvent;
ContentClickProc pContentClick;
CommandProc pCommand;
PrintPageProc pPrintPage;
CalculateIdleTimeProc pCalculateIdleTime;
GetCoachRectangleProc pGetCoachRectangle;
// controls that the default implementations use
void* hPrint; // print record, gxJob, or NIL for none
Boolean hasGrow; // has a grow box?
Rect contentRect; // content area, minus the scroll bars
short minHSize; // minimum window X size, 0 default
short minVSize; // minimum window Y size, 0 default
ControlRef hScroll; // horizontal scroll bar
ControlRef vScroll; // vertical scroll bar
short hScrollAmount; // amount to scroll in left/right arrow
short vScrollAmount; // amount to scroll in up/down arrow
short hScrollOffset; // offset of scrollbar from left side of window
short vScrollOffset; // offset of scrollbar from top of window
// variables having to do with input support
TSMTERecHandle docTSMRecHandle; // TSM info stored here
TSMDocumentID docTSMDoc; // TSM document id
// Custom data follows here
};
typedef struct WindowDataRecord WindowDataRecord, *WindowDataPtr;
// Window adjustment routines
OSErr AdjustScrollBars(WindowRef pWindow, Boolean moveControls, Boolean didGrow, Boolean *needInvalidate);
void SetControlAndClipAmount(ControlRef control, short * amount);
OSErr DoScrollContent(WindowRef pWindow, WindowDataPtr pData, short deltaH, short deltaV);
// document rectangle utilities
void LongRectToRect(LongRect* longRect, Rect *rect);
void RectToLongRect(Rect *rect, LongRect *longRect);
void MovableModalDialog(ModalFilterProcPtr filterProc, short * pItem);
void BeginMovableModal(void);
void EndMovableModal(void);
void GetPICTRectangleAt72dpi(PicHandle hPicture, Rect *pictureRect);
// menu command utilities
void EnableCommand(short commandID);
void EnableCommandCheck(short commandID, Boolean check);
void EnableCommandCheckStyle(short commandID, Boolean check, short style);
void ChangeCommandName(short commandID, short resourceID, short resourceIndex);
Boolean IsCommandEnabled(short commandID);
// printing utility routines
Boolean IsSomewhereInRectangle(gxRectangle *pContainer, gxRectangle *pShape);
OSErr DoDefault(WindowDataPtr pData);
OSErr DoPageSetup(WindowRef pWindow);
// event handling routines
void HandleEvent(EventRecord *);
void DragAndDropArea(WindowRef pWindow, WindowDataPtr pData, EventRecord* event, Rect *pFrameRect);
short ConductFindOrReplaceDialog(short dialogID);
Boolean PerformSearch(
Handle h, // handle to search
long start, // offset to begin with
Str255 searchString, // string to search for
Boolean isCaseSensitive, // case sensitive search
Boolean isBackwards, // search backwards from starting point
Boolean isWraparound, // wrap search around from end->begining
long * pNewStart, // returned new selection start
long * pNewEnd); // returned new selection end
// Drag utils
Boolean IsOnlyThisFlavor(DragReference theDragRef, FlavorType theType);
Boolean IsDropInFinderTrash(AEDesc *dropLocation);
Boolean DragText(WindowRef pWindow, void *pData, EventRecord *pEvent, RgnHandle hilightRgn);
OSErr TextDragTracking(WindowRef pWindow, void *pData, DragReference theDragRef, short message);
OSErr TextDragReceive(WindowRef pWindow, void *pData, DragReference theDragRef);
// TEClick utilities
pascal void TextClickLoop(void);
pascal TEClickLoopUPP GetOldClickLoop(void);
void AdjustTE(WindowDataPtr pData, Boolean doScroll);
// error utilities
void ConductErrorDialog(OSErr error, short commandID, short alertType);
// generic utilities
void SetWatchCursor(void);
OSErr SaveCurrentUndoState(WindowDataPtr pData, short newCommandID);
#if GENERATINGPOWERPC
pascal void MyDrawHook ( unsigned short offset, unsigned short textLen,
Ptr textPtr, TEPtr tePtr, TEHandle teHdl );
#else
pascal void MyDrawHook ( TEHandle teHdl, TEPtr tePtr, Ptr textPtr, short textLen, short offset );
#endif
// Preflight routines for the windows we support
OSErr AboutPreflightWindow(PreflightPtr pPreflightData);
OSErr PICTPreflightWindow(PreflightPtr pPreflightData);
OSErr MoviePreflightWindow(PreflightPtr pPreflightData);
OSErr ClipboardPreflightWindow(PreflightPtr pPreflightData);
OSErr TextPreflightWindow(PreflightPtr pPreflightData);
OSErr GXPreflightWindow(PreflightPtr pPreflightData);
OSErr ThreeDPreflightWindow(PreflightPtr pPreflightData);
// File type routines for the document kinds we support
void AboutGetFileTypes(OSType * pFileTypes, OSType * pDocumentTypes, short * numTypes);
void PICTGetFileTypes(OSType * pFileTypes, OSType * pDocumentTypes, short * numTypes);
void MovieGetFileTypes(OSType * pFileTypes, OSType * pDocumentTypes, short * numTypes);
void ClipboardGetFileTypes(OSType * pFileTypes, OSType * pDocumentTypes, short * numTypes);
void TextGetFileTypes(OSType * pFileTypes, OSType * pDocumentTypes, short * numTypes);
void GXGetFileTypes(OSType * pFileTypes, OSType * pDocumentTypes, short * numTypes);
void ThreeDGetFileTypes(OSType * pFileTypes, OSType * pDocumentTypes, short * numTypes);
// selection rectangle utilities
#define MOVESELECTION(X) (((X) & 0x7) == 0x4)
void DrawSelection(WindowDataPtr pData, Rect *pSelection, short * pPhase, Boolean bumpPhase);
OSErr SelectContents(WindowRef pWindow, WindowDataPtr pData, EventRecord *pEvent, Rect *pSelection, Rect *pContent, short *pPhase);
// Exported globals
struct FontMappingRecord
{
gxFont fontID;
short qdFont;
Style qdStyle;
};
typedef struct FontMappingRecord FontMappingRecord, *FontMappingPtr, **FontMappingHandle;
extern FontMappingHandle gFontMappingList;
#endif
// defined window kinds and resource ranges for windows we support
#define kAboutWindow 'ABOT'
#define kAboutBaseID 200
#define kPICTWindow 'PICT'
#define kPICTBaseID 300
#define kMovieWindow 'MooV'
#define kMovieBaseID 400
#define kClipboardWindow 'Clip'
#define kClipboardBaseID 500
#define kTextWindow 'TEXT'
#define kTextBaseID 600
#define kGXWindow 'qdgx'
#define kGXBaseID 700
#define kThreeDWindow '3DMF'
#define kThreeDBaseID 800
#endif